import { Component, OnInit, Input } from '@angular/core';
// import * as Highcharts from 'highcharts';

import { NavController, ActionSheetController, AlertController } from 'ionic-angular';
import { MarketingHomeService } from "./home.service";
import { Common } from "../../../providers/common";
import { DomSanitizer } from '@angular/platform-browser';
import _ from "lodash";

@Component({
  selector: 'page-marketing-home',
  templateUrl: 'home.html',
  providers: [MarketingHomeService]
})
export class MarketingHomePage implements OnInit {
  moa_page_name: any = "page-marketing-home";
  moa_page_explain: any = "营销首页";

  @Input() public isFromMainPage: boolean;


  ngOnInit(): void {
    if(this.isFromMainPage){
      // this.ngAfterViewInit();
    }
  }

  Title_CompanyScaleTrend = {
    all_capitalColor: "",
    gm_capitalColor: "",
    sb_capitalColor: "",
    zh_capitalColor: "",
    all_capital: null,
    all_capitalDiff: null,
    gm_capital: null,
    gm_capitalDiff: null,
    sb_capital: null,
    sb_capitalDiff: null,
    zh_capital: null,
    zh_capitalDiff: null
  };
  Title_GMGoin = {
    allcapitalColor: "",
    huobcapitalColor: "",
    nhuobcapitalColor: "",
    allcapital: null,
    huobcapital: null,
    nhuobcapital: null,
    allcapitalDiff: null,
    huobcapitalDiff: null,
    nhuobcapitalDiff: null
  };
  Title_ImportantChancel = {
    up: [],
    down: []
  };
  Title_ImportantOrganization = {
    up: [],
    down: []
  };
  Title_GMProductInvest = {
    up: [],
    down: []
  };
  Title_ZHProductInvest = {
    up: [],
    down: []
  };

  gmProductInvestUp = [];
  gmProductInvestDown = [];
  zhProductInvestUp = [];
  zhProductInvestDown = [];

  isAdmin = false;

  currentDate = "";

  constructor(public navCtrl: NavController,
    public alertCtrl: AlertController,
    public homeService: MarketingHomeService,
    private sanitizer: DomSanitizer,
    private actionSheetCtrl: ActionSheetController,
    public common: Common) {

  }

  ngAfterViewInit() {
    if (this.isFromMainPage) {
      this.initData();
    }
  }

  ionViewDidEnter() {
    if (!this.isFromMainPage) {
      this.initData();
    }
  }

  initData() {
    this.homeService.getDataGridFromRedis().subscribe(result => {
      this.isAdmin = result.isAdmin;
      this.initDataGrid(result);
    });
  }

  initDataGrid(result) {
    console.log(result);
    if (result.CompanyScaleTrendDatas && result.CompanyScaleTrendDatas.length > 0) {
      this.currentDate = result.CompanyScaleTrendDatas[result.CompanyScaleTrendDatas.length - 1]["sk_date"];
      this.currentDate = this.currentDate.substr(0, 4) + "-" + this.currentDate.substr(4, 2) + "-"
        + this.currentDate.substr(6, 2);
      this.CompanyScaleTrend(result.CompanyScaleTrendDatas);
    }
    if (result.GMCoinDatas && result.GMCoinDatas.length > 0) {
      this.GMCoin(result.GMCoinDatas);
    }
    if (result.ImportantChancelDatas && result.ImportantChancelDatas.length > 0) {
      this.ImportantChancel(result.ImportantChancelDatas);
    }
    if (result.ImportantOrganizationDatas && result.ImportantOrganizationDatas.length > 0) {
      this.ImportantOrganization(result.ImportantOrganizationDatas);
    }
    if (result.GMProductInvest && result.GMProductInvest.length > 0) {
      this.GMProductInvest(result.GMProductInvest);
    }
    if (result.ZHProductInvest && result.ZHProductInvest.length > 0) {
      this.ZHProductInvest(result.ZHProductInvest);
    }
  }

  moreOp() {
    let bottons = [{
      text: '生成',
      handler: () => {
        this.homeService.generateDataGrid().subscribe(result => {
          if (result && result.isSuccess) {
            let alert = this.alertCtrl.create({
              title: "提示",
              message: "后台正生成数据，请一分钟后执行刷新操作",
              buttons: [
                {
                  text: "确定",
                  role: 'cancel',
                  handler: () => {
                  }
                }
              ]
            });
            alert.present();
          }
        });
      }
    }, {
      text: '刷新',
      handler: () => {
        this.homeService.refreshDataGrid().subscribe(result => {
          this.initDataGrid(result);
        });
      }
    }, {
      text: '发布',
      handler: () => {
        let confirm = this.alertCtrl.create({
          title: '提示',
          message: "您确定要发布吗？",
          enableBackdropDismiss: false,
          buttons: [{
            text: '取消',
            role: 'cancel',
            handler: () => {

            }
          }, {
            text: '确定',
            handler: () => {
              this.homeService.publishDataGrid().subscribe(result => {
                let message = "";
                if (result.isSuccess) {
                  this.initDataGrid(result["requestData"]);
                  message = "发布成功";
                } else {
                  message = "发布失败";
                }
                let alert = this.alertCtrl.create({
                  title: "提示",
                  message: message,
                  buttons: [
                    {
                      text: "确定",
                      role: 'cancel',
                      handler: () => {
                      }
                    }
                  ]
                });
                alert.present();
              });
            }
          }]
        });
        confirm.present();
      }
    }, {
      text: '回滚',
      handler: () => {
        let confirm = this.alertCtrl.create({
          title: '提示',
          message: "您确定要回滚吗？",
          enableBackdropDismiss: false,
          buttons: [{
            text: '取消',
            role: 'cancel',
            handler: () => {

            }
          }, {
            text: '确定',
            handler: () => {
              this.homeService.rollBackDataGrid().subscribe(result => {
                let message = "";
                if (result.isSuccess) {
                  this.initDataGrid(result.requestData);
                  message = "数据已回滚";
                } else {
                  message = "数据回滚失败";
                }
                let alert = this.alertCtrl.create({
                  title: "提示",
                  message: message,
                  buttons: [
                    {
                      text: "确定",
                      role: 'cancel',
                      handler: () => {
                      }
                    }
                  ]
                });
                alert.present();
              });
            }
          }]
        });
        confirm.present();
      }
    }, {
      text: '取消',
      role: 'cancel',
      handler: () => {
      }
    }];

    let actionSheet = this.actionSheetCtrl.create({
      title: '',
      buttons: bottons
    });
    actionSheet.present();
  }

  ZHProductInvest(datas) {
    let temp = _.concat([], datas);
    this.zhProductInvestUp = temp.splice(0, 5);
    this.Title_ZHProductInvest.up = [];
    _.forEach(this.zhProductInvestUp, (up, i) => {
      let currColor: string = "";
      if (!up.netvalue) {
        up.netvalue = "--";
      }
      if (!up.yield_thisyear || up.yield_thisyear === "%") {
        up.yield_thisyear = "--";
        currColor = "black";
      } else {
        currColor = parseFloat(up.yield_thisyear) > 0 ? "red" : "green";
      }
      // currColor = parseFloat(up.yield_thisyear) > 0 ? "red" : "green";
      let temp: any = {
        color: currColor,
        name: up.productname,
        data: up.yield_thisyear
      };
      this.Title_ZHProductInvest.up.push(temp);
      up.yield_thisyear = "<span style='color:" + currColor + "'>" + up.yield_thisyear
        + "</span>";
      up.yield_thisyear = this.sanitizer.bypassSecurityTrustHtml(up.yield_thisyear);
    });
    this.zhProductInvestDown = datas.splice(5, datas.length - 1);
    this.Title_ZHProductInvest.down = [];
    _.forEach(this.zhProductInvestDown, (down, i) => {
      let currColor: string = "";
      if (!down.netvalue) {
        down.netvalue = "--";
      }
      if (!down.yield_thisyear || down.yield_thisyear === "%") {
        down.yield_thisyear = "--";
        currColor = "black";
      } else {
        currColor = parseFloat(down.yield_thisyear) > 0 ? "red" : "green";
      }
      // currColor = parseFloat(down.yield_thisyear) > 0 ? "red" : "green",
      let temp: any = {
        color: currColor,
        name: down.productname,
        data: down.yield_thisyear
      };
      this.Title_ZHProductInvest.down.push(temp);
      down.yield_thisyear = "<span style='color:" + currColor + "'>" + down.yield_thisyear
        + "</span>";
      down.yield_thisyear = this.sanitizer.bypassSecurityTrustHtml(down.yield_thisyear);
    });
  }

  GMProductInvest(datas) {
    let temp = _.concat([], datas);
    this.gmProductInvestUp = temp.splice(0, 5);
    this.Title_GMProductInvest.up = [];
    _.forEach(this.gmProductInvestUp, (up, i) => {
      let currColor: string = "";
      if (!up.sfrank_thisyear) {
        up.sfrank_thisyear = "--";
      }
      if (!up.netvalue) {
        up.netvalue = "--";
      }
      if (!up.yield_thisyear) {
        up.yield_thisyear = "-";
        currColor = "black";
      } else {
        currColor = parseFloat(up.yield_thisyear) > 0 ? "red" : "green";
      }
      let temp: any = {
        color: currColor,
        name: up.productname,
        data: up.yield_thisyear
      };
      this.Title_GMProductInvest.up.push(temp);
      up.yield_thisyear = "<span style='color:" + currColor + "'>" + up.yield_thisyear + "</span>";
      up.yield_thisyear = this.sanitizer.bypassSecurityTrustHtml(up.yield_thisyear);
    });
    this.gmProductInvestDown = datas.splice(5, datas.length - 1);
    this.Title_GMProductInvest.down = [];
    _.forEach(this.gmProductInvestDown, (down, i) => {
      let currColor: string = "";
      if (!down.sfrank_thisyear) {
        down.sfrank_thisyear = "--";
      }
      if (!down.netvalue) {
        down.netvalue = "--";
      }
      if (!down.yield_thisyear) {
        down.yield_thisyear = "-";
        currColor = "black";
      } else {
        currColor = parseFloat(down.yield_thisyear) > 0 ? "red" : "green";
      }
      // let currColor: string = parseFloat(down.yield_thisyear) > 0 ? "red" : "green",
      let temp: any = {
        color: currColor,
        name: down.productname,
        data: down.yield_thisyear
      };
      this.Title_GMProductInvest.down.push(temp);
      down.yield_thisyear = "<span style='color:" + currColor + "'>" + down.yield_thisyear + "</span>";
      down.yield_thisyear = this.sanitizer.bypassSecurityTrustHtml(down.yield_thisyear);
    });
  }

  ImportantOrganization(datas) {
    let series = [];
    console.log(datas);
    let titleDatas = [];
    _.forEach(datas, (data, i) => {
      let temp_series = {
        name: "",
        data: new Array(datas.length).fill(0)
      };
      temp_series.data[parseInt(i)] = parseFloat(data["changecapital"]);
      console.log(temp_series)

      //data["changecapital"] = parseFloat(parseFloat(data["changecapital"]).toFixed(2));
      // data["changecapital"] = parseFloat(data["changecapital"]);
      let temp = "";
      if (parseFloat(data["changecapital"]) > 0) {
        temp_series["name"] = "环比增长";
        temp_series["color"] = "#FFB03B";
        temp = "<span style='color: red;'>" + data["changecapital"] + "亿元</span>";
      } else {
        temp_series["name"] = "环比增长";
        temp_series["color"] = "#7CB5EC";
        temp = "<span style='color: green;'>" + _.replace(data["changecapital"], "-", "") + "亿元</span>";
      }
      series.push(temp_series);
      titleDatas.push(temp);
    });

    console.log(datas);
    this.Title_ImportantOrganization.up = [];
    this.Title_ImportantOrganization.down = [];
    _.forEach(datas, (td, i: number) => {
      let temp = {
        color: "",
        name: "",
        data: null
      };
      temp.name = td["managername"];
      temp.data = td["changecapital"];
      temp.color = +temp.data > 0 ? "redColor" : "greenColor";
      temp.data = _.replace(temp.data, "-", "");
      if (i < 5) {
        this.Title_ImportantOrganization.up.push(temp);
      } else {
        this.Title_ImportantOrganization.down.push(temp);
      }
    });

    /*this.Title_ImportantOrganization = "截至" + this.currentDate + "，近一个月重点机构规模变动中，" +
     up + "处于上涨区间，" + down + "处于下行区间。";

     this.Title_ImportantOrganization = this.sanitizer.bypassSecurityTrustHtml(this.Title_ImportantOrganization);*/

    let elements = document.getElementsByClassName("ImportantOrganization");
    _.forEach(elements, el => {
      window["Highcharts"].chart({
        chart: {
          renderTo: el,
          type: 'column'
        },
        title: {
          text: ' '
        },
        subtitle: {
          text: "规模变动额(亿)"
        },
        xAxis: {
          categories: _.map(datas, "managername"),
          labels: {
            rotation: -90
          }
        },
        plotOptions: {
          column: {
            stacking: 'normal'
          }
        },
        yAxis: {
          title: {
            align: "middle",
            // rotation: 0,
            // offset: 0,
            // y: 0,
            // x: 50,
            text: ''
          }
        },
        navigation: {
          buttonOptions: {
            enabled: false
          }
        },
        legend: {
          verticalAlign: 'top',
          // margin: 35,
          enabled: false
        },

        series: series

      });
    });
  }

  ImportantChancel(datas) {
    let series = [];
    console.log(datas);
    let titleDatas = [];
    _.forEach(datas, (data, i) => {
      let temp_series = {
        name: "",
        data: new Array(datas.length).fill(0)
      };

      let accuracy = data["changecapital"].split(".");
      if (accuracy && accuracy[0]) {
        if (accuracy[0].length < 2) {
          temp_series.data[parseInt(i)] = parseFloat(window["Highcharts"].numberFormat(parseFloat(data["changecapital"]), 2));
        } else {
          temp_series.data[parseInt(i)] = parseFloat(window["Highcharts"].numberFormat(parseFloat(data["changecapital"]), accuracy[0].length));
        }

      }
      // temp_series.data[parseInt(i)] = parseFloat(data["changecapital"]);
      //data["changecapital"] = parseFloat(parseFloat(data["changecapital"]).toFixed(2));
      // data["changecapital"] = parseFloat(data["changecapital"]);
      let temp = "";
      if (parseFloat(data["changecapital"]) > 0) {
        temp_series["name"] = "环比增长";
        temp_series["color"] = "#FFB03B";
        temp = "<span style='color: red;'>" + data["changecapital"] + "亿</span>";
      } else {
        temp_series["name"] = "环比增长";
        temp_series["color"] = "#7CB5EC";
        temp = "<span style='color: green;'>" + _.replace(data["changecapital"], "-", "") + "亿元</span>";
      }

      series.push(temp_series);
      titleDatas.push(temp);
    });
    this.Title_ImportantChancel.up = [];
    this.Title_ImportantChancel.down = [];
    _.forEach(datas, (td, i: number) => {
      let temp = {
        color: "",
        name: "",
        data: null
      };
      temp.name = td["agencyname"];
      temp.data = td["changecapital"];
      temp.color = +temp.data > 0 ? "redColor" : "greenColor";
      temp.data = _.replace(temp.data, "-", "");
      if (i < 5) {
        this.Title_ImportantChancel.up.push(temp);
      } else {
        this.Title_ImportantChancel.down.push(temp);
      }
    });

    /*this.Title_ImportantChancel = "截止至" + this.currentDate + "，近一个月重点渠道规模变动中，"
     + datas[0]["agencyname"] + "(" + titleDatas[0] +
     ")、" + datas[1]["agencyname"] + "(" + titleDatas[1] + ")、" + datas[2]["agencyname"] +
     "(" + titleDatas[2] + ")、" + datas[3]["agencyname"] + "(" + titleDatas[3] + ")、" + datas[4]["agencyname"] +
     "(" + titleDatas[4] + ")处于上涨区间，" + datas[5]["agencyname"] + "(" + titleDatas[5] + ")、" + datas[6]["agencyname"] +
     "(" + titleDatas[6] + ")、" + datas[7]["agencyname"] + "(" + titleDatas[7] + ")、" + datas[8]["agencyname"] +
     "(" + titleDatas[8] + ")、" + datas[9]["agencyname"] + "(" + titleDatas[9] + ")处于下行区间。";

     this.Title_ImportantChancel = this.sanitizer.bypassSecurityTrustHtml(this.Title_ImportantChancel);*/

    // datas[0]["agencyname"] += "asdfasdfasdfasdfafafadsfasdf";

    if (datas[0]["agencyname"].length > 8) {
      datas[0]["agencyname"] = datas[0]["agencyname"].substr(0, 8) + "...";
    }

    let elements = document.getElementsByClassName("ImportantChancel");
    _.forEach(elements, el => {
      window["Highcharts"].chart({
        chart: {
          renderTo: el,
          type: 'column'
        },
        title: {
          text: ' '
        },
        subtitle: {
          text: "规模变动额(亿)"
        },
        xAxis: {
          categories: _.map(datas, "agencyname"),
          overflow: "false",
          useHTML: true,
        },

        yAxis: {
          title: {
            align: "high",
            // rotation: 0,
            // offset: 0,
            // y: 0,
            // x: 100,
            text: ''
          }
        },
        navigation: {
          buttonOptions: {
            enabled: false
          }
        },
        plotOptions: {
          column: {
            stacking: 'normal'
          }
        },
        legend: {
          verticalAlign: 'top',
          margin: 35,
          enabled: false
        },

        series: series

      });
    });

  }

  /**
   * 公募货币非货币规模变动
   * @constructor
   */
  GMCoin(datas) {
    console.log(datas);

    this.Title_GMGoin.allcapital = datas[datas.length - 1]["allcapital"];
    this.Title_GMGoin.huobcapital = datas[datas.length - 1]["huobcapital"];
    this.Title_GMGoin.nhuobcapital = datas[datas.length - 1]["nhuobcapital"];

    _.forEach(datas, data => {
      data["sk_date"] = data["sk_date"].substr(0, 4) + "-" + data["sk_date"].substr(4, 2)
        + "-" + data["sk_date"].substr(6, 2);
      data["allcapital"] = parseFloat(data["allcapital"]);
      data["huobcapital"] = parseFloat(data["huobcapital"]);
      data["nhuobcapital"] = parseFloat(data["nhuobcapital"]);
    });

    this.Title_GMGoin.allcapitalDiff = this.countDiff(datas, "allcapital");
    this.Title_GMGoin.huobcapitalDiff = this.countDiff(datas, "huobcapital");
    this.Title_GMGoin.nhuobcapitalDiff = this.countDiff(datas, "nhuobcapital");

    if (this.Title_GMGoin.allcapitalDiff.indexOf("-") > -1) {
      this.Title_GMGoin.allcapitalColor = "greenColor";
      this.Title_GMGoin.allcapitalDiff = this.removeSign(this.Title_GMGoin.allcapitalDiff);
    } else {
      this.Title_GMGoin.allcapitalColor = "redColor";
    }

    if (this.Title_GMGoin.huobcapitalDiff.indexOf("-") > -1) {
      this.Title_GMGoin.huobcapitalColor = "greenColor";
      this.Title_GMGoin.huobcapitalDiff = this.removeSign(this.Title_GMGoin.huobcapitalDiff);
    } else {
      this.Title_GMGoin.huobcapitalColor = "redColor";
    }

    if (this.Title_GMGoin.nhuobcapitalDiff.indexOf("-") > -1) {
      this.Title_GMGoin.nhuobcapitalColor = "greenColor";
      this.Title_GMGoin.nhuobcapitalDiff = this.removeSign(this.Title_GMGoin.nhuobcapitalDiff);
    } else {
      this.Title_GMGoin.nhuobcapitalColor = "redColor";
    }

    // this.Title_GMGoin = "截至" + this.currentDate + "，公司公募货币非货币总资产：" +
    //   datas[datas.length - 1]["allcapital"] + "亿，环比：" + allcapitalDiff + "，其中货币类资产：" +
    //   datas[datas.length - 1]["huobcapital"] + "亿，环比：" + huobcapitalDiff + "，非货币类资产：" +
    //   datas[datas.length - 1]["nhuobcapital"] + "亿，环比：" + nhuobcapitalDiff + "。";
    // this.Title_GMGoin = this.sanitizer.bypassSecurityTrustHtml(this.Title_GMGoin);

    let tickPixelInterval = parseInt(_.toString(datas.length / 4));
    console.log(tickPixelInterval);
    let huobcapitalDatas = _.map(datas, "huobcapital");
    this.markPoint(huobcapitalDatas, 0);
    this.markPoint(huobcapitalDatas, tickPixelInterval);
    this.markPoint(huobcapitalDatas, tickPixelInterval * 2);
    this.markPoint(huobcapitalDatas, tickPixelInterval * 3);
    this.markPoint(huobcapitalDatas, tickPixelInterval * 4);

    let nhuobcapitalDatas = _.map(datas, "nhuobcapital");
    this.markPoint(nhuobcapitalDatas, 0);
    this.markPoint(nhuobcapitalDatas, tickPixelInterval);
    this.markPoint(nhuobcapitalDatas, tickPixelInterval * 2);
    this.markPoint(nhuobcapitalDatas, tickPixelInterval * 3);
    this.markPoint(nhuobcapitalDatas, tickPixelInterval * 4);

    let elements = document.getElementsByClassName("GMCoin");
    _.forEach(elements, el => {
      window["Highcharts"].chart({
        chart: {
          renderTo: el,
          type: 'line'
        },
        title: {
          text: ' '
        },
        subtitle: {
          text: " "
        },
        xAxis: {
          tickInterval: tickPixelInterval,
          gridLineWidth: 1,
          categories: _.map(datas, "sk_date")
        },

        yAxis: {
          title: {
            align: "high",
            rotation: 0,
            offset: 0,
            y: -15,
            x: 0,
            text: '资产(亿元)'
          },
          labels: {
            format: '{value}'
          }
        },
        navigation: {
          buttonOptions: {
            enabled: false
          }
        },
        legend: {
          verticalAlign: 'top',
          enabled: true,
          margin: 35
        },

        tooltip: {
          shared: true,
          crosshairs: true
        },

        plotOptions: {
          series: {
            cursor: 'pointer',
            point: {
              events: {
                click: function (e) {

                }
              }
            },
            marker: {
              enabled: false,
              states: {
                hover: { enabled: true }
              }
            }
          }
        },

        series: [{
          name: '货币类资产',
          data: huobcapitalDatas
        }, {
          name: '非货币类资产',
          color: "#8B5A2B",
          data: nhuobcapitalDatas
        }]

      });
    });
  }

  /**
   * 公司规模走势图
   * @constructor
   */
  CompanyScaleTrend(datas) {

    console.log(datas);

    this.Title_CompanyScaleTrend.all_capital = datas[datas.length - 1]["all_capital"];
    this.Title_CompanyScaleTrend.gm_capital = datas[datas.length - 1]["gm_capital"];
    this.Title_CompanyScaleTrend.sb_capital = datas[datas.length - 1]["sb_capital"];
    this.Title_CompanyScaleTrend.zh_capital = datas[datas.length - 1]["zh_capital"];

    _.forEach(datas, data => {
      data["sk_date"] = data["sk_date"].substr(0, 4) + "-" + data["sk_date"].substr(4, 2)
        + "-" + data["sk_date"].substr(6, 2);
      data["all_capital"] = parseFloat(data["all_capital"]);
      data["gm_capital"] = parseFloat(data["gm_capital"]);
      data["sb_capital"] = parseFloat(data["sb_capital"]);
      data["zh_capital"] = parseFloat(data["zh_capital"]);

    });

    this.Title_CompanyScaleTrend.all_capitalDiff = this.countDiff(datas, "all_capital");
    this.Title_CompanyScaleTrend.gm_capitalDiff = this.countDiff(datas, "gm_capital");
    this.Title_CompanyScaleTrend.sb_capitalDiff = this.countDiff(datas, "sb_capital");
    this.Title_CompanyScaleTrend.zh_capitalDiff = this.countDiff(datas, "zh_capital");

    if (this.Title_CompanyScaleTrend.all_capitalDiff.indexOf("-") > -1) {
      this.Title_CompanyScaleTrend.all_capitalColor = "greenColor";
      this.Title_CompanyScaleTrend.all_capitalDiff = this.removeSign(this.Title_CompanyScaleTrend.all_capitalDiff);
    } else {
      this.Title_CompanyScaleTrend.all_capitalColor = "redColor";
    }

    if (this.Title_CompanyScaleTrend.gm_capitalDiff.indexOf("-") > -1) {
      this.Title_CompanyScaleTrend.gm_capitalColor = "greenColor";
      this.Title_CompanyScaleTrend.gm_capitalDiff = this.removeSign(this.Title_CompanyScaleTrend.gm_capitalDiff);
    } else {
      this.Title_CompanyScaleTrend.gm_capitalColor = "redColor";
    }

    if (this.Title_CompanyScaleTrend.sb_capitalDiff.indexOf("-") > -1) {
      this.Title_CompanyScaleTrend.sb_capitalColor = "greenColor";
      this.Title_CompanyScaleTrend.sb_capitalDiff = this.removeSign(this.Title_CompanyScaleTrend.sb_capitalDiff);
    } else {
      this.Title_CompanyScaleTrend.sb_capitalColor = "redColor";
    }

    if (this.Title_CompanyScaleTrend.zh_capitalDiff.indexOf("-") > -1) {
      this.Title_CompanyScaleTrend.zh_capitalColor = "greenColor";
      this.Title_CompanyScaleTrend.zh_capitalDiff = this.removeSign(this.Title_CompanyScaleTrend.zh_capitalDiff);
    } else {
      this.Title_CompanyScaleTrend.zh_capitalColor = "redColor";
    }

    let tickPixelInterval = parseInt(_.toString(datas.length / 4));
    console.log(tickPixelInterval);
    let all_capitalDatas = _.map(datas, "all_capital");
    this.markPoint(all_capitalDatas, 0);
    this.markPoint(all_capitalDatas, tickPixelInterval);
    this.markPoint(all_capitalDatas, tickPixelInterval * 2);
    this.markPoint(all_capitalDatas, tickPixelInterval * 3);
    this.markPoint(all_capitalDatas, tickPixelInterval * 4);

    let gm_capitalDatas = _.map(datas, "gm_capital");
    this.markPoint(gm_capitalDatas, 0);
    this.markPoint(gm_capitalDatas, tickPixelInterval);
    this.markPoint(gm_capitalDatas, tickPixelInterval * 2);
    this.markPoint(gm_capitalDatas, tickPixelInterval * 3);
    this.markPoint(gm_capitalDatas, tickPixelInterval * 4);

    let sb_capitalDatas = _.map(datas, "sb_capital");
    this.markPoint(sb_capitalDatas, 0);
    this.markPoint(sb_capitalDatas, tickPixelInterval);
    this.markPoint(sb_capitalDatas, tickPixelInterval * 2);
    this.markPoint(sb_capitalDatas, tickPixelInterval * 3);
    this.markPoint(sb_capitalDatas, tickPixelInterval * 4);

    let zh_capitalDatas = _.map(datas, "zh_capital");
    this.markPoint(zh_capitalDatas, 0);
    this.markPoint(zh_capitalDatas, tickPixelInterval);
    this.markPoint(zh_capitalDatas, tickPixelInterval * 2);
    this.markPoint(zh_capitalDatas, tickPixelInterval * 3);
    this.markPoint(zh_capitalDatas, tickPixelInterval * 4);

    let temp = this.common.getPreMonth("2017-03-31");
    console.log(temp);

    let elements = document.getElementsByClassName("CompanyScaleTrend");
    _.forEach(elements, el => {
      window["Highcharts"].chart({
        chart: {
          renderTo: el
        },
        title: {
          text: '',
          style: {
            "display": "none"
          }
        },
        subtitle: {
          text: "",
          style: {
            "display": "none"
          }
        },
        xAxis: {
          tickInterval: tickPixelInterval,
          gridLineWidth: 1,
          categories: _.map(datas, "sk_date")
        },

        yAxis: {
          tickInterval: 1000,
          title: {
            align: "high",
            rotation: 0,
            offset: 0,
            y: -20,
            x: 0,
            text: '资产(亿元)'
          },
          labels: {
            format: '{value}'
          }
        },
        navigation: {
          buttonOptions: {
            enabled: false
          }
        },
        legend: {
          width: 220,
          // itemWidth: 115,
          align: "center",
          verticalAlign: 'top',
          margin: 35,
          y: 0,
          enabled: true
        },

        tooltip: {
          shared: true,
          crosshairs: true
        },

        plotOptions: {
          series: {
            cursor: 'pointer',
            point: {
              events: {
                click: function (e) {

                }
              }
            },
            marker: {
              enabled: false,
              lineWidth: 1,
              states: {
                hover: { enabled: true }
              }
            }
          }
        },

        series: [{
          name: '资产总计',
          color: 'Crimson',
          data: all_capitalDatas
        }, {
          name: '公募资产',
          color: '#8B5A2B',
          data: gm_capitalDatas
        }, {
          name: '专户资产',
          color: 'DarkOrange',
          data: zh_capitalDatas
        }, {
          name: '社保养老金资产',
          color: 'CornflowerBlue',
          data: sb_capitalDatas
        }]

      });
    });
  }

  markPoint(datas, index) {
    if (index >= datas.length) {
      return;
    }
    datas[index] = {
      y: datas[index],
      marker: {
        enabled: true
      }
    }
  }

  countDiff(datas, fieldName) {
    let diff = null;
    let currentItem = datas[datas.length - 1];
    let currentDate = currentItem["sk_date"];
    let preDate = this.common.getPreMonth(currentDate);
    console.log(preDate);
    let preItem = _.find(datas, { "sk_date": preDate });
    if (preItem) {
      diff = (currentItem[fieldName] - preItem[fieldName]) / preItem[fieldName] * 100;
    } else {
      diff = currentItem[fieldName] * 100;
    }
    diff = diff.toFixed(2);
    return _.toString(diff) + "%";
  }

  removeSign(str: string): string {
    return str.replace(/-+/gi, "");
  }
}

